﻿using FMStudio.Documents;
using FMStudio.Templates.DesignTool.Application.Properties;
using System;
using System.ComponentModel.DataAnnotations;

namespace FMStudio.Templates.DesignTool.Application.Models
{
    public class DocumentItem : ToolboxItem
    {
        #region Fields
        private bool targetChanged;
        
        private DocumentType<Document> documentType;
        private string fileName;
        private string targetFileName;
        private bool replaceParameter;
        #endregion

        public DocumentItem(DocumentType<Document> documentType)
            : base(Resources.Document)
        {
            this.documentType = documentType;

            this.targetChanged = false;
        }

        #region Properties
        internal DocumentType<Document> DocumentType
        {
            get { return this.documentType; }
        }

        public string DocumentTypeName { get { return this.documentType.GetType().Name; } }

        [Required]
        public string FileName
        {
            get { return this.fileName; }
            set
            {
                if (this.fileName != value)
                {
                    this.fileName = value;
                    RaisePropertyChanged("FileName");
                    if (!this.targetChanged)
                    {
                        this.targetFileName = value;
                        RaisePropertyChanged("TargetFileName");
                    }
                }
            }
        }

        [Required]
        public string TargetFileName
        {
            get { return this.targetFileName; }
            set
            {
                if (this.targetFileName != value)
                {
                    this.targetFileName = value;
                    RaisePropertyChanged("TargetFileName");
                    this.targetChanged = true;
                }
            }
        }

        public bool ReplaceParameter
        {
            get { return this.replaceParameter; }
            set
            {
                if (this.replaceParameter != value)
                {
                    this.replaceParameter = value;
                    RaisePropertyChanged("ReplaceParameter");
                }
            }
        }
        #endregion
    }
}
